/**
  *2020年7月23日上午9:06:49
  */
package com.cy.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.cy.pojo.Userdto;
import com.cy.service.LoginService;
import com.cy.service.ZhuceService;
@Controller
@RequestMapping("/")
public class LoginController {
//	尝试提交
//	用户登录 service 查找数据库
//	成功跳转主页面
	@Autowired
	LoginService loginService;
	private static Cookie cookie;
	
	@RequestMapping("dologin")
	public String doLogin(){
		return "log.htm";
	}
	@RequestMapping(value ="dologinzhuce", method = {RequestMethod.POST})
	@ResponseBody
	public String dozhuce(@RequestBody Userdto userdto,HttpServletRequest request){
		System.out.println(userdto);
		return "log.htm";
	}
	
	/*
	 * @RequestMapping(value="logworing", method = {RequestMethod.GET})
	 * 
	 * @ResponseBody public Userdto getLogin(Userdto userdto) { if
	 * (loginService.userLogin(userdto)==0) { System.out.println("用户名错误"); return
	 * userdto; } else { System.out.println("密码错误"); return userdto; }
	 * 
	 * }
	 */

	@RequestMapping(value = "dowebdemo", method = {RequestMethod.POST})
	public String dowebdemoindex(Userdto userdto,HttpServletResponse response){

		System.out.println(userdto);
		
		ModelAndView mav=new ModelAndView();
		
		
		if (loginService.userLogin(userdto)!=1) {
			cookie = new Cookie("login","false");
			response.addCookie(cookie);
			return "log.htm";
			
			
		}else {
			cookie = new Cookie("login","true");
			response.addCookie(cookie);
			return "webdemoindex";
		}
		
		
	}
	
}
